#!/bin/bash

echo "================================"
echo "启动后端前台服务 (端口 8081)"
echo "================================"
echo ""

# 进入后端目录
cd "/Users/kevin/项目文件夹/交易平台/newsite/trading-center-backend" || exit 1

# 检查 Docker 容器
echo "1. 检查 Docker 容器状态..."
MYSQL_STATUS=$(docker ps --filter "name=ryp_scm_mysql" --format "{{.Status}}" | grep -i "Up")
REDIS_STATUS=$(docker ps --filter "name=ryp_scm_redis" --format "{{.Status}}" | grep -i "Up")

if [ -z "$MYSQL_STATUS" ]; then
    echo "❌ MySQL 容器未运行，正在启动..."
    docker start ryp_scm_mysql
    sleep 5
else
    echo "✅ MySQL 容器正在运行"
fi

if [ -z "$REDIS_STATUS" ]; then
    echo "❌ Redis 容器未运行，正在启动..."
    docker start ryp_scm_redis
    sleep 3
else
    echo "✅ Redis 容器正在运行"
fi

echo ""
echo "2. 启动后端前台服务..."
echo "================================"
echo "访问地址："
echo "  API: http://localhost:8081"
echo "  Swagger: http://localhost:8081/doc.html"
echo "================================"
echo ""
echo "⏳ 服务启动需要 1-2 分钟，请耐心等待..."
echo "💡 看到 'Started CrmebFrontApplication' 表示启动成功"
echo ""

cd crmeb-front || exit 1
mvn spring-boot:run -Dspring-boot.run.profiles=dev
